﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;

namespace SmartMeterParamFrame
{
    public class ApplocationDoEvents
    {
        private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);

        public static void DoEvents()
        {
            DispatcherFrame nestedFrame = new DispatcherFrame();

            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(

                                                                            DispatcherPriority.Background, exitFrameCallback, nestedFrame);

            Dispatcher.PushFrame(nestedFrame);

            if (exitOperation.Status != DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }

        private static Object ExitFrame(Object state)
        {

            DispatcherFrame frame = state as DispatcherFrame;

            frame.Continue = false;

            return null;

        }
    }
}
